package com.huatai.datacenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.common.util.StringUtil;
import com.huatai.datacenter.entity.subject.SubjectDirectoryEntity;
import com.huatai.datacenter.mapper.SubjectDirectoryMapper;
import com.huatai.datacenter.service.SubjectDirectoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gusiyi
 * @version 1.0
 * @className SubjectDirectoryServiceImpl
 * @description 描述：
 * @date 2023/6/6 11:14
 */
@Service
public class SubjectDirectoryServiceImpl extends ServiceImpl<SubjectDirectoryMapper, SubjectDirectoryEntity> implements SubjectDirectoryService {

	@Override
	public Page<SubjectDirectoryEntity> getSubList(SubjectDirectoryEntity subjectDirectoryEntity) {
		String subjectDirectoryName = subjectDirectoryEntity.getSubjectDirectoryName();
		LambdaQueryWrapper<SubjectDirectoryEntity> subjectQuery = Wrappers.lambdaQuery();
		subjectQuery
				.eq(subjectDirectoryEntity.getTypeContent() != null,
						SubjectDirectoryEntity::getTypeContent,
						subjectDirectoryEntity.getTypeContent())
			.eq(SubjectDirectoryEntity::getDeleted,false)
			.like(StringUtil.isNotBlank(subjectDirectoryName),SubjectDirectoryEntity::getSubjectDirectoryName, subjectDirectoryName)
			.orderByDesc(SubjectDirectoryEntity::getUpdateTime);
		Page<SubjectDirectoryEntity> page = new Page<>(subjectDirectoryEntity.getPageIndex(),subjectDirectoryEntity.getPageSize());
		return page(page, subjectQuery);
	}

	@Override
	public boolean deleteByIds(List<SubjectDirectoryEntity> subjectDirectoryEntityIds) {
		for (SubjectDirectoryEntity subjectDirectoryEntityId : subjectDirectoryEntityIds) {
			subjectDirectoryEntityId.setDeleted(true);
		}
		return updateBatchById(subjectDirectoryEntityIds);
	}
}
